<?php

namespace Apps\Common\Models;

/**
 * 用户的相关属性值Model
 * @author     chenxiaolin
 * @date        2016年1月19日
 * @version     2.0.0
 * @copyright   Copyright 2016 meelier.com
 */
class UserAttribute extends \PhalconPlus\Database\Model
{

    /**
     *
     * @var integer
     */
    public $attr_id;

    /**
     *
     * @var integer
     */
    public $user_id;

    /**
     *
     * @var integer
     */
    public $attr_type;

    /**
     *
     * @var string
     */
    public $attr_key;

    /**
     *
     * @var integer
     */
    public $attr_value_number;

    /**
     *
     * @var string
     */
    public $attr_value_datetime;

    /**
     *
     * @var string
     */
    public $attr_value_json;

    /**
     *
     * @var string
     */
    public $attr_value_text;

    /**
     *
     * @var string
     */
    public $attr_value_geometry;

    /**
     *
     * @var double
     */
    public $attr_value_decimal2;

    /**
     *
     * @var integer
     */
    public $attr_state;

    /**
     *
     * @var string
     */
    public $attr_update_time;

    /**
     *
     * @var string
     */
    public $attr_addtime;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->belongsTo('user_id', 'Apps\Common\Models\UserBase', 'user_id', array('alias' => 'UserBase'));
        $this->belongsTo('attr_type', 'Apps\Common\Models\UserAttributeType', 'type_id', array('alias' => 'UserAttributeType'));
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'user_attribute';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return UserAttribute[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return UserAttribute
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * Independent Column Mapping.
     * Keys are the real names in the table and the values their names in the application
     *
     * @return array
     */
    public function columnMap()
    {
        return array(
            'attr_id' => 'attr_id',
            'user_id' => 'user_id',
            'attr_type' => 'attr_type',
            'attr_key' => 'attr_key',
            'attr_value_number' => 'attr_value_number',
            'attr_value_datetime' => 'attr_value_datetime',
            'attr_value_json' => 'attr_value_json',
            'attr_value_text' => 'attr_value_text',
            'attr_value_geometry' => 'attr_value_geometry',
            'attr_value_decimal2' => 'attr_value_decimal2',
            'attr_state' => 'attr_state',
            'attr_update_time' => 'attr_update_time',
            'attr_addtime' => 'attr_addtime'
        );
    }

    public function defaultColumns()
    {
        return [
            'attr_value_number',
            'attr_value_datetime',
            'attr_value_json',
            'attr_value_text',
            'attr_value_geometry',
            'attr_value_decimal2',
            'attr_state',
            'attr_update_time',
            'attr_addtime',
        ];
    }

}
